var express = require('express');
var app = express();
var bodyParser = require('body-parser');

var multer = require('multer');

upload = multer({dest:'upload'});

app.use(bodyParser.urlencoded({extended:true}));
app.use(bodyParser.json());

app.get('/api/v1/people',function(req,res){
  res.set('my-custom-header','Angular rocks');
  res.json([{name:'张三',age:2},{name:'李四',age:22}]);
});

app.post('/api/v1/people',function(req,res){
  res.json(req.body);
})

app.post('/api/v1/people/123/avatar',upload.single('avatar'),function(res){
  res.send(res.file);
})

var port = 3000;

app.listen(port);

console.log('App is running at port ' + port);
